package tester.outcome.group;

import state.group.events.BaseEvent;
import state.group.events.EventCollection;
import state.group.events.EventType;
import state.group.events.RegistrationEvent;
import tester.outcome.BaseEventOutcome;
import messages.observer.EventCollectionMessage;

/**
 * This class with check for registration message from an elevator connecting with the GD
 * @author Caleb Chan
 *
 */
public class RegistrationEventOutcome extends BaseEventOutcome {

	private byte elevatorId;
	
	/**
	 * RegistrationEventOutcome constructor
	 * @param startTime The start time of the outcome
	 * @param elevatorId The elevator that registered
	 */
	public RegistrationEventOutcome(long startTime, byte elevatorId) {
		super(startTime);
		this.elevatorId = elevatorId;
	}

	@Override
	public boolean checkOutcome(EventCollectionMessage message) {
		
		EventCollection collection = message.getEvents();
		
		for(BaseEvent e : collection){
			// Checks for a registration event
			if (e.getEventType() == EventType.RegistrationEvent){
				RegistrationEvent rE = (RegistrationEvent)e;
				// Checks for the right elevator id
				if (rE.getElevatorId() == elevatorId){
					isCompleted = true;
				}
			}
		}
		
		return isCompleted;
	}

	@Override
	public String getOutcomeName() {
		return "RegistrationEventOutcome";
	}

	@Override
	public BaseEventOutcome copy() {
		return new RegistrationEventOutcome(0, elevatorId);
	}

	@Override
	public String getOutcomeChecksStr() {
		return getOutcomeName() + " Elevator -> " + elevatorId;
	}

}
